<?php Tag::css('scaffold') ?>
<div id="scaffold">
    <?php View::content(); ?>    
    <h1>Video: <span>crear</span></h1>                        
    <?php if(isset($youtube_id)): ?>
    
        <?php 
                $c = curl_init('http://gdata.youtube.com/feeds/api/videos/'.$youtube_id.'' );
                curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
                $page = curl_exec($c);
                curl_close($c); 
                $sxe = new SimpleXMLElement($page);
                $titulo= $sxe->title;
                $descripcion= $sxe->content; 
                $duracion= $sxe->yt; 
        ?>
        <iframe width="560" height="315" src="http://www.youtube.com/embed/<?php echo $youtube_id; ?>?rel=0" frameborder="0" allowfullscreen="allowfullscreen"></iframe>
        <?php echo Form::open(null, 'post', 'class="scaffold"') ?>
        <label for="videos_titulo" class="required">Titulo <em>*</em></label>
        <?php echo Form::text('videos.titulo','',$titulo) ?>        
        <label for="videos_descripcion" class="required">Descripcion <em>*</em></label>
        <?php echo Form::text('videos.descripcion',"style='width:430px; height:80px;'",$descripcion) ?>        
        <label for="videos_video" class="required">Video <em>*</em></label>
        <?php echo Form::text('videos.video','',$youtube_id) ?>     
        <label for="videos_img" class="required">Imagen <em>*</em></label>
        <?php echo Form::text('videos.img','',$youtube_id) ?>                                    
        <label for="videos_categorias" class="required">Categoria <em>*</em> </label>       
        <?php echo Form::dbSelect('categorias_id', 'nombre',array('categorias', 'find'), '-- seleccione categoria --') ?>
        <div id="div_subcategoria">
        <label for="videos_subcategorias_id" class="required">Subcategorias <em>*</em> </label>       
        <?php echo Form::dbSelect('videos.subcategorias_id', 'nombre',array('subcategorias', 'find'), '-- seleccione subcategoria --') ?>
        </div>
        <label for="videos_estatus" class="required">Estatus <em>*</em></label>       
        <?php echo estatus::select('videos') ?>    
        <input type="submit" value="Enviar" />
        <?php echo Form::close() ?>
        
    <?php else: ?>
        
        <?php echo Form::open(null, 'post', 'class="scaffold"') ?>
        <label for="url" class="required">Url</label>
        <?php echo Form::text('url') ?>                
        <input type="submit" value="Enviar" />
        <?php echo Form::close() ?>
        
    <?php endif; ?>
        
    <div class="actions">
        <a href="../">Listado</a>
    </div>
</div>

<script type='text/javascript'>
$("#categorias_id").change(function(){ // Asigna el evento change al combo de marcas
	var categoria_id 	=	$('#categorias_id').val();
        $.ajax({
          type: "POST",
          url: "<?php echo PUBLIC_PATH . 'index/getSubcategorias/'; ?>",
          data: "categoria_id=" + categoria_id,
          success: function(html){
            $("#div_subcategoria").html(html);
          }
        });
});
</script>